package com.ruizhong.centercontroll.controller;


//import com.ruizhong.centercontroll.config.MinIoClientConfig;
import com.ruizhong.centercontroll.service.FileService;
import com.ruizhong.centercontroll.util.CosUtil;
import com.ruizhong.centercontroll.util.Result;
import com.ruizhong.centercontroll.util.ResultCode;
import lombok.extern.slf4j.Slf4j;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/file/api")
@CrossOrigin
@Slf4j
public class FileController {

    @Autowired
    private FileService fileService;


//    @Autowired
//    private MinIoClientConfig minIoClientConfig;

    @PostMapping("/submitFile")
    public Result submitDeviceListFile(@RequestBody MultipartFile file) {
//        String url = fileService.uploadFile(file);
        return new Result(ResultCode.success, "提交成功", null);
    }

    @PostMapping("/upload/{resourceServerIp}")
    public Result upload(@RequestBody MultipartFile file,@PathVariable(value = "resourceServerIp") String resourceServerIp) throws IOException {
        String url = fileService.uploadFile(file,resourceServerIp);
        return new Result(ResultCode.success, "上传成功", url);
    }

    @DeleteMapping("/deleteFile")
    public Result deleteFile(@RequestBody List<String> deleteFileList) throws Exception {
        fileService.deleteFile(deleteFileList);
        return new Result(ResultCode.success, "删除成功", null);
    }

    @PostMapping("/submitToCOS")
    public Result submitToCOS(@RequestBody MultipartFile file) throws IOException {
        CosUtil cosUtil = new CosUtil();
        String url = cosUtil.upLoad(file);
        return new Result(ResultCode.success, "上传成功", url);
    }
}
